//
//  YFIntegralAreaHeaderView.m
//  QuanJieShopProject
//
//  Created by apple on 2018/5/29.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YFIntegralAreaHeaderView.h"
#import "SDCycleScrollView.h"

@interface YFIntegralAreaHeaderView()
@property (nonatomic, strong) SDCycleScrollView *cycleView;

@end


@implementation YFIntegralAreaHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = YFColor_Background;
        [self makeView];
    }
    return self;
}


- (void)makeView {
    
    // 网络加载图片的轮播器  420
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT * 420.f/1334.f) delegate:self placeholderImage:[UIImage imageNamed:@"HBanner"]];
    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"banner_dian"];
    cycleScrollView.pageDotImage = [UIImage imageNamed:@"banner_kong"];
    [self addSubview:cycleScrollView];
    cycleScrollView.delegate = self;
    self.cycleView = cycleScrollView;
    
#warning 这个view需要抽取出来
    // 为你优选  75
    CGFloat lineW = 0.5;
    CGFloat chooseViewH = 75.f/1334.f *UISCREEN_HEIGHT;
    UIView *chooseView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(cycleScrollView.frame), UISCREEN_WIDTH, chooseViewH)];
    chooseView.backgroundColor = YFColor_Background;
    //    chooseView.backgroundColor = [UIColor blueColor];
    [self addSubview:chooseView];
    {
        CGFloat tipLableW = 100;
        CGFloat tipLabelH = chooseViewH;
        UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tipLableW, tipLabelH)];
        tipLabel.center = CGPointMake(chooseView.mj_w/2, chooseViewH/2);
        tipLabel.text = @"为你优选";
        tipLabel.textAlignment = NSTextAlignmentCenter;
        tipLabel.textColor = YFColor_Text;
        tipLabel.font = [UIFont systemFontOfSize:13];
        [chooseView addSubview:tipLabel];
        
        CGFloat lineWidth = (chooseView.mj_w - tipLableW)/2;
        UIView *leftLine = [[UIView alloc] initWithFrame:CGRectMake(0, tipLabelH/2, lineWidth, lineW)];
        leftLine.backgroundColor = [UIColor colorWithHexString:@"dddddd"];
        [chooseView addSubview:leftLine];
        
        UIView *rightLine = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(tipLabel.frame), tipLabelH/2, lineWidth, lineW)];
        rightLine.backgroundColor = [UIColor colorWithHexString:@"dddddd"];
        [chooseView addSubview:rightLine];
    }
    
    
//    self.height = CGRectGetMaxY(chooseView.frame);
}

- (void)setBannerArray:(NSMutableArray *)bannerArray {
    _bannerArray = bannerArray;
    
    NSLog(@"bannerArray = %zd", bannerArray.count);
    
    // 拼接图片地址 应该是最初的字典解析力做这个
    NSMutableArray *array = [NSMutableArray array];
    for (int i = 0; i < bannerArray.count; i++) {
        HbannerModel *model = bannerArray[i];
        NSString *bannerUrl = [NSString stringWithFormat:@"%@%@",NET_BASEURL_IMG,model.ad_code];
        NSLog(@"bannerUrl = %@", bannerUrl);
        [array addObject:bannerUrl];
    }
    self.cycleView.imageURLStringsGroup = array;
    kWeakSelf;
    self.cycleView.clickItemOperationBlock = ^(NSInteger currentIndex) {
//        if (weakSelf.clickItemOperationBlock) {
//            weakSelf.clickItemOperationBlock(currentIndex);
//        }
    };
    
}




@end
